﻿/*
2009-6-17
comm:window对象的属性,程序里直接使用;
comm的属性--initialize,返回一个对象,对象有:setarr\getarr函数,
comm.fun中封装共用的方法,通过setarr\getarr函数调用
不需要返回值,调用comm.fun.***()
*/
var comm=window.comm={};
comm.fun={
    a:"",
    b:"",
    c:"",
    arr:[],
    init:function(){
        comm.fun.a="";
        comm.fun.b="";
        comm.fun.c="";
        comm.fun.moveElem();
    },
    moveElem:function(){
        var i=comm.fun.arr.length;
        if(i) comm.fun.arr.splice(0,i);
    },
    method:function(){
        var _mname = "",_paramA = "",_paramB = "",_model = "",_str = "",_arr = [];        
        if($("#radioLine").attr("checked") == true) 
        {
            _mname = "LinerModel";
            _model = $("#txtLine").val();            
        }
        if($("#radioExp").attr("checked") == true) 
        {
            _mname = "ExpModel";
            _model = $("#txtExp").val();
        }
        if($("#radioLn").attr("checked") == true) 
        {
            _mname = "LogModel";
            _model = $("#txtLn").val();
        }
        if(_model=="")  return;
        _str = _model.split('=')[1];
        _arr = _str.split('+');
        _paramA = _arr[0];
        _str = _arr[1].split(')')[0];
        _paramB = _str.split('(')[1];
        comm.fun.a=_paramA;
        comm.fun.b=_paramB;
        comm.fun.c=_mname;
        //comm.fun.arr.push(_paramA,_paramB,_mname);
        return [_paramA,_paramB,_mname];
    },
    method_1:function(){
        var _g = "",_l = "",_c = "";
        if($("#chk_default").attr("checked")==true)
        {
            _g="system,0";_l="system";_c = "system";
            //return;
        }else
        {
            var _num = $("#GraduationNumber").val();
            if (_num > 0)
            {
                var lastValue = 0;
                for (var i = 0; i < _num; i++)
                {
                    var graValue = eval($("#Graduation" + i)).val();
                    if (graValue.length == 0) {alert("请填写完整的刻度分级数值！");return;}
                    if(!isDigit(graValue)) {alert("您填写的分级刻度包含非数值字符，请重新填写！");return;}
                    if(graValue < lastValue) {alert("您填写的分级刻度值小于零或者小于上一级刻度值，请重新检查！");return;}
                    _g += graValue + ",";
                    lastValue = parseFloat(graValue);
                    var graLabel = eval($("#Label" + i)).val();
                    if(graLabel.length==0) {alert("请填写分级的描述文字！");return;}
                    _l += graLabel + ","; 
                    var graColor = eval($("#Color" + i)).val();
                    if(graColor.length==0) {alert("请输入分级的颜色！");return;}
                    _c += graColor + ",";
                }
            }else
            {
                alert("请填写分级的数值！");
                return;
            }
        }
        
        //comm.fun.arr.push(_g,_l,_c);    
        return [_g,_l,_c];
    },
    method_2:function(){
        var mapSize = gmap.getBounds(); 
        var southWest = mapSize.getSouthWest();
        var northEast = mapSize.getNorthEast();
        var lngDelta = (northEast.lng() - southWest.lng()) / 2;
        var latDelta = (northEast.lat() - southWest.lat()) / 2;
        var rectBounds = new GLatLngBounds(
            new GLatLng(southWest.lat() - latDelta,southWest.lng() - lngDelta),
            new GLatLng(northEast.lat() + latDelta, northEast.lng() + lngDelta));        
        var mapEast = parseInt(10000*rectBounds.getNorthEast().lng())/10000;
        var mapNorth = parseInt(10000*rectBounds.getNorthEast().lat())/10000;
        var mapWest = parseInt(10000*rectBounds.getSouthWest().lng())/10000;
        var mapSouth = parseInt(10000*rectBounds.getSouthWest().lat())/10000;
        var mb = mapWest + "," + mapEast +  "," + mapNorth +  "," + mapSouth;
        //comm.fun.a=mb;
        return [mb,rectBounds];
    },
    method_district:function(sltP,sltC){
        if (parseInt(USER_DISTRICT_ID) == 0 )
        {
            var _opText = ["北京","河北","吉林","黑龙江","江苏","山东","河南","湖南","浙江","新疆"];
            var _opValue = ["1","5","9","10","11","16","17","19","12","31"];
            var _ops  = createOptions(_opValue,_opText);
            for(var i = 0; i < _opText.length; i++)
                sltP.options.add(_ops[i]);            
            fillCountySelect();       
            $(sltP).bind("change",fillCountySelect);            
            $(sltC).bind("change",function(){
                var pid= $(sltC).val();
                
                $.get("Services/getDistrictList.aspx",{DISTID:pid,TEMP:Math.random()},function(data){
                    var xmlDocument = data.documentElement;
                    var nodes = xmlDocument.getElementsByTagName("District");
                    var strLc=nodes[0].attributes[2].nodeValue+","+nodes[0].attributes[3].nodeValue;
                    GLoadMap(strLc,10);
                });
            });
        }
        else
        {
            if (parseInt(USER_DISTRICT_ID) == 1 )
            {                
                var _ocText = ["全省（市、区）","大兴","通州","顺义","昌平","密云","平谷","怀柔","延庆","房山","丰台","门头沟","石景山","海淀","朝阳","中心四城区"];
                var _ocValue = ["1","74","71","72","73","78","76","75","77","70","66","69","67","68","65","61"];
                var _ocs  = createOptions(_ocValue,_ocText);
                for(var i = 0; i < _ocs.length; i++)                
                    sltC.options.add(_ocs[i]);   
                    
                $(sltC).bind("change",function(){
                    var pid= $(sltC).val();
                    
                    $.get("Services/getDistrictList.aspx",{DISTID:pid,TEMP:Math.random()},function(data){
                        var xmlDocument = data.documentElement;
                        var nodes = xmlDocument.getElementsByTagName("District");
                        var strLc=nodes[0].attributes[2].nodeValue+","+nodes[0].attributes[3].nodeValue;
                        GLoadMap(strLc,10);
                    });
                });    
                                            
            }
            else if (parseInt(USER_DISTRICT_ID) < 50)
            {                
                strUrl = "Services/getDistrictList.aspx";
                var strLc="";
                $.get(strUrl,{DISTID:USER_DISTRICT_ID, TEMP:Math.random()},function(data){
                      var xmlDocument = data.documentElement;
                      //var nDistricts = xmlDocument.childNodes.length;
                      var nodes = xmlDocument.getElementsByTagName("District");
                      var nDistricts=nodes.length;
                      var _ocText = [];
                      var _ocValue = [];
                      _ocText[0] = "全省（市、区）";
                      _ocValue[0] = USER_DISTRICT_ID;
                      
                      strLc=nodes[0].attributes[2].nodeValue+","+nodes[0].attributes[3].nodeValue;
                      for(var i = 0; i < nDistricts; i++)
                      {
                        //_ocText[i] = xmlDocument.childNodes[i].attributes[1].nodeValue;
                        //_ocValue[i] = xmlDocument.childNodes[i].attributes[0].nodeValue;
                        _ocText[i + 1] = nodes[i].attributes[1].nodeValue;
                        _ocValue[i + 1] = nodes[i].attributes[0].nodeValue;
                      }
                      var _ocs  = createOptions(_ocValue,_ocText);
                      for(var i = 0; i < _ocs.length; i++)                                  
                          sltC.options.add(_ocs[i]); 
                          
                      $(sltC).bind("change",function(){
                          var pid= $(sltC).val();
                            
                          $.get("Services/getDistrictList.aspx",{DISTID:pid,TEMP:Math.random()},function(data){
                              var xmlDocument = data.documentElement;
                              var nodes = xmlDocument.getElementsByTagName("District");
                              var strLc=nodes[0].attributes[2].nodeValue+","+nodes[0].attributes[3].nodeValue;
                              GLoadMap(strLc,10);
                          });
                      });
                        //GLoadMap(strLc,10);                                 
               });
            }
            else
            {
                var _ocText = [USER_DISTRICT_NAME];
                var _ocValue = [USER_DISTRICT_ID];
                var _ocs  = createOptions(_ocValue,_ocText);
                for(var i = 0; i < _ocs.length; i++)                
                    sltC.options.add(_ocs[i]);                            
            }
        }
    },
    method_default:function(chk,txts,lebs,cols){
        for(var i = 0; i < chk.length; i++)
            $(chk[i]).bind("click",function(){
                if($("#defGraduations").attr("checked") == true)
                {
                    for(var j = 0; j < txts.length; j++) 
                        $(txts[j]).attr("disabled",true);
                }
                else
                {
                    for(var j = 0; j < txts.length; j++) 
                        $(txts[j]).attr("disabled",false);
                }                
                if($("#defLabels").attr("checked") == true)
                {
                    for(var j = 0; j < txts.length; j++) 
                        $(lebs[j]).attr("disabled",true);
                }
                else
                {
                    for(var j = 0; j < txts.length; j++) 
                        $(lebs[j]).attr("disabled",false);
                }
                if($("#defColors").attr("checked") == true)
                {
                    for(var j = 0; j < txts.length; j++) 
                        $(cols[j]).attr("disabled",true);
                }
                else
                {
                    for(var j = 0; j < txts.length; j++) 
                        $(cols[j]).attr("disabled",false);
                }
            });
    }
};
comm.initialize=function(){
    var _array=[];
    var o={};
    o["getarr"]=function(){ return _array;};
    o["setarr"]=function(para){
        //初始化变量清空数组
        comm.fun.init();    
        var p=para || "equation";    
        switch(p)
        {
            case "equation":_array= comm.fun.method();break;
            case "grade":_array= comm.fun.method_1(); break;
        }
    };
    return o;
}




            /*
            if($("#defGraduations").attr("checked") == true)
            { _g = "system," + _num; }
            else
            {            
                var lastValue = 0;
                for (var i = 0; i < _num; i++)
                {
                    var graValue = eval($("#Graduation" + i)).val();
                    if (graValue.lenght == 0) {alert("请填写完整的刻度分级数值！");return;}
                    if(!isDigit(graValue)) {alert("您填写的分级刻度包含非数值字符，请重新填写！");return;}
                    if(graValue < lastValue) {alert("您填写的分级刻度值小于零或者小于上一级刻度值，请重新检查！");return;}
                    _g += graValue + ",";
                    lastValue = parseFloat(graValue);
                    var graLabel = eval($("#Label" + i)).val();
                    _l += graLabel + ",";                    
                    var graColor = eval($("#Color" + i)).val();
                    _c += graColor + ",";
                }
            }
            if($("#defLabels").attr("checked") == true) 
            { _l = "system"; }
            else
            {
                for (var i = 0; i < _num; i++)
                {
                    var graLabel = eval($("#Label" + i)).val();
                    _l += graLabel + ",";
                }
            }
            if($("#defColors").attr("checked") == true) 
            { _c = "system"; }
            else
            {
                for (var i = 0; i < _num; i++)
                {
                    var graColor = eval($("#Color" + i)).val();
                    _c += graColor + ",";
                }
            }*/